<script setup>
import {defineProps} from "vue";
import {inject} from "vue";
import {edit} from "../../../apis/user";
import {plus} from "../../../apis/user";


/**
 * 自定义属性 ：只读
 * @type {Prettify<Readonly<ExtractPropTypes<{visible: BooleanConstructor}>>>}
 */

const props=defineProps({
  title: String,
  formData:Object

})
/**
 * 注入父组件中传入的值
 * @type {unknown}
 */
const dialogVisible=inject('dialogVisible')
const isSuccess=inject('isSuccess')

const save = () =>{
  if(props.title == '修改'){
    // console.log(props.formData)
    edit(props.formData).then(()=>{
      dialogVisible.value=false
      isSuccess.value=true
    })
  }else if(props.title == '新增'){
     plus(props.formData).then(()=>{
       dialogVisible.value=false
       isSuccess.value=true
     })
  }

}


</script>


<template>
  <el-dialog :title="props.title" width="500" align-center  v-model="dialogVisible">
    <el-form>
      <el-form-item label="用户名">
      <el-input v-model="props.formData.username"/>
    </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="props.formData.password"/>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="props.formData.nickname"/>
      </el-form-item>
      <el-form-item label="性别">
        <el-input v-model="props.formData.gender"/>
      </el-form-item>
      <el-form-item label="状态">
        <el-input v-model="props.formData.status"/>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="props.formData.phone"/>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="props.formData.email"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="save">
          保存
        </el-button>
      </div>
    </template>
  </el-dialog>


</template>


<style scoped>

</style>